<template>
    <div class="con_box">
        <!-- 搜索栏目开始
        <div class="search_column">
            <el-form ref="searchForm" :inline="true" :model="table.queryParams" label-width="95px" size="mini">
                <el-form-item label="轮播图：">
                    <el-input v-model="table.queryParams.keyWord"></el-input>
                </el-form-item>
                <el-form-item label="">
                    <el-button type="primary" size="small" icon="el-icon-search" @click="searchSubmit">查 询</el-button>
                    <el-button type="primary" size="small" icon="el-icon-refresh" @click="resetSubmit(table.queryParams)">重置</el-button>
                </el-form-item>
            </el-form>
        </div> -->
        <!-- 搜索栏目结束 -->
        <!-- 操作栏开始 -->
        <div class="btns_column clearfix">
            <div class="fl">
                <el-button type="primary" size="mini" icon="el-icon-plus" @click="toAdd">添加轮播图</el-button>
            </div>
            <div class="fr">
                <!--  <a v-has="'student:import'" href="javascript:void(0)" @click="downloadTemplate" class="link_txt">
                    下载导入模板
                </a> -->
            </div>
        </div>
        <!-- 操作栏结束 -->
        <vue-table :api-url="table.apiUrl" :fields="table.fields" :appendParams="table.queryParams" :content="self" ref="tableList">
        </vue-table>
        <user-add ref="dictionaryAdd"></user-add>
        <user-detail ref="userDetail"></user-detail>
    </div>
</template>

<script>
    import user_add from "./backend_add"
    import user_detail from "./backend_detail"
    import moment from 'moment'
    export default {
        components: {
            "user-add": user_add,
            "user-detail": user_detail,
        },
        data() {
            return {
                self: this,
                table: {
                    apiUrl: api.backendsManagement.backendList,
                    queryParams: {
                        type: ''
                    },
                    fields: [{
                        prop: "__index",
                            width: "60",
                            label: "序号",
                        },
                        {
                            prop: "typeName",
                            label: "类型",
                        },
                        {
                            prop: "title",
                            width: "150",
                            label: "标题",
                        },
                        {
                            prop: "description",
                            width: "150",
                            label: "描述",
                        },
                        {
                            prop: "link",
                            label: "地址",
                        },
                        {
                            prop: "sort",
                            label: "排序",
                        },
                        {
                            prop: "shopName",
                            label: "商店名称",
                        },
                        {
                            prop: "__action",
                            label: "操作",
                            width: 100,
                            actions: [
                                // {
                                //     label: "重置密码",
                                //     type: "edit",
                                //     func: function(vm, row) {
                                //         vm.resetPassword(row.id);
                                //     }
                                // },
                                // {
                                //     label: "详情",
                                //     type: "edit",
                                //     func: function(vm, row) {
                                //         vm.$refs.userDetail.showDialog(row);
                                //     }
                                // },
                                {
                                    label: "编辑",
                                    type: "edit",
                                    func: function(vm, row) {
                                        vm.$refs.dictionaryAdd.showDialog(row);
                                    }
                                },
                                {
                                    label: "删除",
                                    type: "delete",
                                    func: function(vm, row) {
                                        vm.deleteDictionary(row.id);
                                    }
                                }
                            ]
                        }
                    ],
                },
            }
        },
        methods: {
            // 查询
            searchSubmit() {
                this.$refs.tableList.$emit('vuetable:refresh');
            },
            //重置
            resetSubmit(val) {
                for (var key in val) {
                    val[key] = '';
                }
                this.$refs.tableList.$emit('vuetable:refresh');
            },
            // 添加
            toAdd() {
                this.$refs.dictionaryAdd.showDialog();
            },
            // 用户详情
            toUserDetail() {
                this.$refs.userDetail.showDialog();
            },
            // 删除用户
            deleteDictionary(id) {
                let vm = this;
                vm.$confirm('是否删除该条记录！', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                    .then(() => {
                        vm.axios.delete(api.backendsManagement.backendList+'/'+id)
                        .then((response) => {
                            if(response.data.success){
                                vm.$message.success(response.data.message);
                                vm.$refs.tableList.$emit('vuetable:current-refresh');
                            }else{
                                vm.$message.error(response.data.message);
                            }
                        });
                    }, () => {})
            },
            // 重置密码
            resetPassword(id) {
                let vm = this;
                vm.$confirm('是否重置此用户密码！', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                    .then(() => {
                        // vm.axios.delete(api.userManagement.resetPasswordList.replace(/\{id\}/, id))
                        // .then((response) => {
                        //     if(response.data.success){
                        //         vm.$message.success(response.data.message);
                        //         vm.$refs.tableList.$emit('vuetable:current-refresh');
                        //     }else{
                        //         vm.$message.error(response.data.message);
                        //     }
                        // });
                    }, () => {})
            },
        },
        mounted() {}
    }
</script>